package com.software.graduationproject.modules.shopping.web;

import com.baomidou.mybatisplus.core.metadata.Page;

import com.software.graduationproject.commons.select.Select;
import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.shopping.object.ShoppingCartPocketVo;
import com.software.graduationproject.modules.shopping.object.ShoppingCartVo;
import com.software.graduationproject.modules.shopping.service.ShoppingCartService;
import com.software.graduationproject.modules.shopping.object.ShoppingCartCreateQo;
import com.software.graduationproject.modules.shopping.object.ShoppingCartUpdateQo;


import com.v2coding.validate.CreateGroup;
import com.v2coding.validate.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * ShoppingCartController : 购物车表
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/Shopping/ShoppingCart")
@Api(value = "API - 购物车表", tags = {"购物车表接口"})
public class ShoppingCartController  {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/create")
    @ApiOperation("新增购物车表")
    public Result createQo(@RequestBody @Validated(CreateGroup.class) ShoppingCartCreateQo qo) {
        shoppingCartService.createQo(qo);
        return Results.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改购物车表")
    public Result updateQo(@RequestBody ShoppingCartUpdateQo qo) {
        shoppingCartService.updateQo(qo);
        return Results.success();
    }

//    @PostMapping("/delete")
//    @ApiOperation("删除购物车表")
//    public Result delete(Select select) {
//        shoppingCartService.delete(select);
//        return Results.success();
//    }


    @PostMapping("/deleteList")
    @ApiOperation("批量删除购物车表")
    public Result deleteList(@RequestBody Long []ids) {
        shoppingCartService.deleteList(ids);
        return Results.success();
    }

    @GetMapping("/selectCount")
    @ApiOperation("查询购物车表总数")
    public Result<Integer> selectVo(Select select) {
        Integer count = shoppingCartService.selectCount(select);
        return Results.success(count);
    }

    @GetMapping("/selectPriceAndNum")
    @ApiOperation("查询购物车表总数和价格")
    public Result<ShoppingCartPocketVo> selectPriceAndNum(Select select) {
        ShoppingCartPocketVo shoppingCartPocketVo = shoppingCartService.selectPriceAndNum(select);
        return Results.success(shoppingCartPocketVo);
    }


    @GetMapping("/selectList")
    @ApiOperation("查询购物车表列表")
    @ApiImplicitParams({ //
            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
    })
    public Result<List<ShoppingCartVo>> selectListVo(@ApiIgnore Select select) {
        List<ShoppingCartVo> shoppingCartVoList = shoppingCartService.selectListVo(select);
        return Results.success(shoppingCartVoList);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询购物车表分页")
    @ApiImplicitParams({ //
            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
    })
    public Result<Page<ShoppingCartVo>> selectPageVo(@ApiIgnore Select select) {
        Page<ShoppingCartVo> shoppingCartVoPage = shoppingCartService.selectPageVo(select);
        return Results.success(shoppingCartVoPage);
    }



}
